package com.butte.mound.facade.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.butte.mound.frame.token.BaseToken;
import com.butte.mound.frame.token.TokenContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

@Slf4j
@Component
public class FacadeInterceptor implements HandlerInterceptor {

  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

    log.info("req uri : {}",request.getRequestURI());

    String facadeToken = "zV1UG2hoXrscEDx9MW8TgY42RYVuw8KQi+PmZkxVyhAVgBhWjymoIxTOAm0LHNzLrZal5leEiTHP6zeSEFbwUE6luiNXdfMsa7jDZLb1WWDFAw7Vgl3heBR/o5umemahif99+EHJIiwmlRSONDfhdBhcwSjhl77Rdar2ICsSrhpuAO6YgiKjFGfQtQKU/Nj8";

    String adminToken = "zV1UG2hoXrscEDx9MW8TgYrO/hK4P16KLRv+WmFhrZu+5HdPkUvW/KJcfmay6LYLKFOdr9l/ivEJ1GnfKkfH70iBbTvgHvqTGYr2AMO4kjEkbxcuPVtnM1ZC3Yr98DoLsUOTw7Pys8cfwN377NRbOwCnsD50qRMwJ40/ueNbwQ4=";

    BaseToken token = BaseToken.parseToken(facadeToken);
    TokenContext.setToken(token);

    return Boolean.TRUE ;
  }
}
